// +---------------------------------------------------------------------
// | 潮州市潮安区东凤镇浅沙软件开发工作室
// +---------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.jacinto.cn All rights reserved.
// +---------------------------------------------------------------------
// | Licensed 浅沙建站系统并不是自由软件，未经许可不能去掉浅沙建站系统相关版权
// +---------------------------------------------------------------------
// | Author: 浅沙软件开发工作室 <qs_jacinto@qq.com>
// +---------------------------------------------------------------------
// 权限指令
import { useStore } from '@/store'
import { Directive } from 'vue'

export const acl: Directive = {
  mounted(el, binding) {
    const { value } = binding
    const permissions = useStore().state.user.permissions;
    if(value && value instanceof Array && value.length > 0) {
        const hasPermission = permissions.some((perm: any) => {
            return value.includes(perm)
        })
        if(!hasPermission) {
            el.style.display = 'none';
        }
    }
  }
}
